class Solution(object):
    def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance):
        out = []
        for res in restaurants:
            if res[2] >= veganFriendly and res[3] <= maxPrice and res[4] <= maxDistance:
                out.append(res)
        out.sort(key=lambda x: (x[1], x[0]), reverse=True)
        return [res[0] for res in out]
